# coding=UTF-8
'''
Created on 2018年4月26日

@author: lijie
'''
from businessLayer.page_element.metadata.metadata_add_collection_pop_page import MetaAddCollectionPopPage

class MetaAddCollectionPopPageFun():
        
    def save(self):
        MetaAddCollectionPopPage().BtnSave().click()
        
    def submit(self):
        MetaAddCollectionPopPage().BtnSubmit().click()
        
    def cancel(self):
        MetaAddCollectionPopPage().BtnCancel().click()
        
    def set_collection_info(self,coll_info):
        #输入任务名称
        MetaAddCollectionPopPage().TxtCollectionTaskNAME().check_and_input(coll_info['collName'])
        # 选择元模型
        MetaAddCollectionPopPage().LstBtnMetaModel().click()
        MetaAddCollectionPopPage().Lst1MetaModel().check_and_select_by_item_text(coll_info['datamodel1'])
        MetaAddCollectionPopPage().Lst2MetaModel().check_and_select_by_item_text(coll_info['datamodel2'])
        MetaAddCollectionPopPage().Lst3MetaModel().check_and_select_by_item_text(coll_info['datamodel3'])
        # 选择数据源
        MetaAddCollectionPopPage().LstBtnDataSource().click()
        MetaAddCollectionPopPage().LstDataSource().check_and_select_by_item_text(coll_info['datasource'])
        #选择挂载目录
        if coll_info['directory']!='':
            MetaAddCollectionPopPage().LstBtnDirectory().click()
            MetaAddCollectionPopPage().LstDirectory().select_by_item_text(coll_info['directory'])
            
        # 设置调度方式    
        if coll_info['schedulmode']!='':    
            MetaAddCollectionPopPage().RadSchedulmodeByName(coll_info['schedulmode']).select()
        if coll_info['schedulmode']=='一次性' and coll_info['is_recommend']==True:
            MetaAddCollectionPopPage().LnkRecommendTime().click()
        elif coll_info['schedulmode']=='周期性':
            if coll_info['coll_freq']=='每小时':
                els=MetaAddCollectionPopPage().LstBtnsFreq().elements()
                els[0].click()
                MetaAddCollectionPopPage().LstCollFreq().select_by_item_text(coll_info['coll_freq'])
                els[1].click()
                MetaAddCollectionPopPage().LstFrequecy().select_by_item_text(coll_info['perHour_minute'])
            if coll_info['coll_freq']=='每天':
                els=MetaAddCollectionPopPage().LstBtnsFreq().elements()
                els[0].click()
                MetaAddCollectionPopPage().LstCollFreq().select_by_item_text(coll_info['coll_freq'])
                els[1].click()
                MetaAddCollectionPopPage().LstFrequecy().select_by_item_text(coll_info['perDay_hour'])
                els[2].click()
                MetaAddCollectionPopPage().LstFrequecy().select_by_item_text(coll_info['perDay_minute'])
            if coll_info['coll_freq']=='每周':
                els=MetaAddCollectionPopPage().LstBtnsFreq().elements()
                els[0].click()
                MetaAddCollectionPopPage().LstCollFreq().select_by_item_text(coll_info['coll_freq'])
                els[1].click()
                MetaAddCollectionPopPage().LstFrequecy().select_by_item_text(coll_info['perWeek_day'])  
                els[2].click()
                MetaAddCollectionPopPage().LstFrequecy().select_by_item_text(coll_info['perWeek_hour'])  
                els[3].click()
                MetaAddCollectionPopPage().LstFrequecy().select_by_item_text(coll_info['perWeek_minute']) 
            if coll_info['coll_freq']=='每月':
                els=MetaAddCollectionPopPage().LstBtnsFreq().elements()
                els[0].click()
                MetaAddCollectionPopPage().LstCollFreq().select_by_item_text(coll_info['coll_freq'])
                els[1].click()
                MetaAddCollectionPopPage().LstFrequecy().select_by_item_text(coll_info['perMonth_day'])  
                els[2].click()
                MetaAddCollectionPopPage().LstFrequecy().select_by_item_text(coll_info['perMonth_hour'])  
                els[3].click()
                MetaAddCollectionPopPage().LstFrequecy().select_by_item_text(coll_info['perMonth_minute']) 
            if coll_info['coll_freq']=='每年':
                els=MetaAddCollectionPopPage().LstBtnsFreq().elements()
                els[0].click()
                MetaAddCollectionPopPage().LstCollFreq().select_by_item_text(coll_info['coll_freq'])
                els[1].click()
                MetaAddCollectionPopPage().LstFrequecy().select_by_item_text(coll_info['perYear_month'])  
                els[2].click()
                MetaAddCollectionPopPage().LstFrequecy().select_by_item_text(coll_info['perYear_day'])  
                els[3].click()
                MetaAddCollectionPopPage().LstFrequecy().select_by_item_text(coll_info['perYear_hour'])
                els[4].click()
                MetaAddCollectionPopPage().LstFrequecy().select_by_item_text(coll_info['perYear_minute'])
            MetaAddCollectionPopPage().LblTitle().click()
            
        
        
        
        
        
        